feat(docs): not-found 自动解析历史路径,resolver 命中即 301 单跳#354
Merged
Conversation
- 新建 app/[locale]/docs/not-found.tsx(segment-level not-found): 查询 /api/docs/resolve,命中 doc_paths 历史表就 router.replace 到 新路径,端点返回 404 或 500ms 超时则显示标准 404 UI - next.config.mjs 追加 /api/docs/resolve → backend rewrite 防重定向环三层: 前端层:location === strippedPath 时不跳(canonical == current) 端点层:canonical 来自 path_current(当前文件必然存在) 超时层:500ms AbortController,端点异常直接降级 404 `router.replace` 而非 `push`,后退不回到 not-found 页。
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
app/[locale]/docs/not-found.tsx(segment-level not-found,只对/[locale]/docs/**生效):命中旧 URL 时向/api/docs/resolve查询 doc_paths 历史表,拿到 301+Location 就router.replace到新 URL;端点 404 或超时则显示标准 404 UInext.config.mjs追加/api/docs/resolve → backendrewrite行为
防重定向环(三层)
location === strippedPath时不跳,直接显示 404path_current(实际存在的文件路径),正常不再触发 not-foundAbortController,端点异常直接降级 404,不白屏等待验收
依赖 Block 2 端点(
/api/docs/resolve)merge 到生产后,手动验证以下场景:Test plan
pnpm build通过,TypeScript clean,52 vitest 全绿/[locale]/docs/[...slug]仍 SSG,正常 docs 页不受影响)/api/docs/resolverewrite 本地验证通过(curl 3010 返回 301/404)🤖 Generated with Claude Code